﻿@{
    var user = ViewData["user"] == null ? null : ViewData["user"] as BaseAuthRole.DTO.User.UUIUser;


    var user_role = ViewData["user_role"] == null ? null : ViewData["user_role"] as List<BaseAuthRole.DTO.Role.Role>;

    var title = user == null ? "创建用户" : "编辑用户";

    var roles = ViewData["roles"] as List<BaseAuthRole.DTO.Role.Role>;

    ViewBag.Title = title;

    Layout =  "~/Views/Shared/_ManagerLayoutPage.cshtml";
}

@section ChildPageCss
    {


    <link href="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/vendor/icheck/_all.css" rel="stylesheet" />


}

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-body">
                <p style="font-size:15px;font-weight:bold;">@title</p>
                <ul class="nav nav-list"><li class="divider"></li></ul>
                <div class="form-group ">
                    <lable class="col-sm-2 control-lable require">状态</lable>
                    <div class="col-sm-4">
                        <select id="status" class="form-control" disabled="disabled">

                            <option value="1">正常</option>
                            <option value="0" @(user == null ? "" : user.Status == 0 ? "selected" : "")>无效</option>
                        </select>
                    </div>
                </div>
                <div class="form-group ">
                    <lable class="col-sm-2 control-lable require">姓名</lable>
                    <div class="col-sm-4">
                        <input id="name" class="form-control" value="@(user==null?"":user.Name)" disabled="disabled">
                    </div>
                </div>
                <div class="form-group ">
                    <lable class="col-sm-2 control-lable require">部门</lable>
                    <div class="col-sm-4">
                        <input id="department" class="form-control" value="@(user==null?"":user.Department)" disabled="disabled">
                    </div>
                </div>
                <div class="form-group ">
                    <lable class="col-sm-2 control-lable">职位</lable>
                    <div class="col-sm-4">
                        <input id="jobtitle" class="form-control" value="@(user==null?"":user.JobTitle)" disabled="disabled">
                    </div>
                </div>
                <div class="form-group ">
                    <lable class="col-sm-2 control-lable">职称</lable>
                    <div class="col-sm-4">
                        <input id="title" class="form-control" value="@(user==null?"":user.Title)" disabled="disabled">
                    </div>
                </div>
                <div class="form-group ">
                    <lable class="col-sm-2 control-lable require">工号</lable>
                    <div class="col-sm-4">
                        <input id="jobnumber" class="form-control" value="@(user==null?"":user.JobNumber)" disabled="disabled">
                    </div>
                </div>

                <div class="form-group ">
                    <lable class="col-sm-2 control-lable">专业</lable>
                    <div class="col-sm-4">
                        <input id="profession" class="form-control" value="@(user==null?"":user.Profession)" disabled="disabled">
                    </div>
                </div>

                <div class="form-group ">
                    <lable class="col-sm-2 control-lable require">用户名</lable>
                    <div class="col-sm-4">
                        <input id="loginname" class="form-control" value="@(user==null?"":user.LoginName)" disabled="disabled">
                    </div>
                </div>
                <div class="form-group">
                    <lable class="col-sm-2 control-lable">手机号</lable>
                    <div class="col-sm-4">
                        <input id="phone" class="form-control" value="@(user==null?"":user.Phone)" readonly="@(user!=null&&!string.IsNullOrEmpty(user.Phone))" type="number" disabled="disabled">
                    </div>
                </div>
                <div class="form-group">
                    <lable class="col-sm-2 control-lable require">密码</lable>
                    <div class="col-sm-4">
                        <input id="password" class="form-control" value="" type="password" disabled="disabled">
                    </div>
                </div>
                <div class="form-group">
                    <lable class="col-sm-2">角色</lable>
                    <div class="col-sm-4" id="baseContent">
                        <ul class="roles list-group">

                            @foreach (var o in roles)
                            {
                                <li style="list-style:none;">
                                    <input type="checkbox" id="@o.Id" value="@(o.Id)_@(o.Name)" @(user_role == null ? "" : user_role.Any(p => p.Id == o.Id) ? "checked" : "") />
                                    <label for="@o.Id">@o.Name</label>
                                </li>
                            }
                        </ul>
                    </div>
                </div>



                <div class="form-group">

                    <div class="col-sm-4 col-sm-offset-2">
                        <button class="btn btn-success" onclick="BasicSubmit(this)" type="button">保存</button>
                        @*<button class="btn  btn-outline-secondary" onclick="back()" type="button">返回</button>*@
                    </div>
                </div>
            </div>
            </div>
        </div>
</div>   


        @section ChildPageScript{


    <script src="@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")/Resource/vendor/icheck/icheck.min.js"></script>

            <script>
                $(document).ready(function () {
                    $('.roles input').iCheck({
                        checkboxClass: 'icheckbox_square-green',
                        radioClass: 'iradio_square-green',
                        increaseArea: '20%'
                    });
                });


            </script>
            <script>

        var id = "@Context.Request.Query["id"]";

        function BasicSubmit(obj)
        {
            var name = $("#name").val();

            var loginname = $("#loginname").val();

            var jobnumber = $("#jobnumber").val();

            var department = $("#department").val();

            var jobtitle = $("#jobtitle").val();

            var title = $("#title").val();

            var phone = $("#phone").val();

            var password = $("#password").val();

            var profession = $("#profession").val();

            var roles = GetListValue($(".roles input:checked"));


            var status = $("#status").val();

            if (name == "")
            {
                Notic("warning","名称不能为空");
                return;
            }
            if (password == ""&&id=="")
            {
                Notic("warning", "密码不能为空");
                return;
            }

            //if (phone.length>0&&!checkPhone(phone))
            //{
            //    Notic("warning", "手机号格式有误");
            //    return;

            //}

            $(obj).attr("disabled", "disabled");

             $.ajax({

                url: "@RS.Environment.ConfigurationHelper.GetAppSettings("VirtualUrl")" + "@Url.Action("AddOrUpdateUser", "UserManager")",
                dataType: "json",
                 data: {
                     "id": id, "name": name, "status": status, "phone": phone, "password": password, "roles": roles, "jobnumber": jobnumber,
                     "loginname": loginname, "department": department, "jobtitle": jobtitle, "title": title, "profession": profession
                 },
                type: "post",
                success: function (data) {
                    console.log(data);

                    if (data.IsError)
                    {
                        Notic('error',data.Message);
                    }
                    else
                    {
                        Notic('info', '操作成功');

                    }


                },
                fail: function (data) {


                },
                complete: function (data) {


                    $("#loading").hide();

                    $(obj).removeAttr("disabled");

                }
            });
        }


            </script>

        }
